package com.cn.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cn.gmall.common.result.Result;
import com.cn.gmall.model.product.BaseCategoryTrademark;
import com.cn.gmall.model.product.BaseTrademark;
import com.cn.gmall.model.product.CategoryTrademarkVo;
import com.cn.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {
    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;


    /**删除分类品牌关联
     * admin/product/baseCategoryTrademark/remove/{category3Id}/{trademarkId}
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public  Result removeBaseCategoryTrademark(@PathVariable Long category3Id,@PathVariable Long trademarkId){

        LambdaQueryWrapper<BaseCategoryTrademark> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategoryTrademark::getTrademarkId,trademarkId);
        queryWrapper.eq(BaseCategoryTrademark::getCategory3Id,category3Id);
        baseCategoryTrademarkService.remove(queryWrapper);
        return  Result.ok();
    }



    /**
     * 保存前端传入的参数 用 CategoryTrademarkVo 接
     * @param CategoryTrademarkVo
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody CategoryTrademarkVo CategoryTrademarkVo){
        baseCategoryTrademarkService.saveCategoryTrademark(CategoryTrademarkVo);
        return  Result.ok();
    }

    /**
     * 根据category3Id获取品牌列表
     *
     * @param category3Id
     * @return
     */

    @GetMapping("/findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id) {

        List<BaseTrademark> list = baseCategoryTrademarkService.findTrademarkList(category3Id);
//        不管是不是查询到数据 均返回 ok否则前端报错
        return Result.ok(list);
    }

    /**
     * 根据category3Id获取可选品牌列表
     * @param category3Id
     * @return
     */

    @GetMapping("/findCurrentTrademarkList/{category3Id}")
public  Result findCurrentTrademarkList(@PathVariable Long category3Id){
        List<BaseTrademark> list = baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
//        不管是不是查询到数据 均返回 ok否则前端报错
        return Result.ok(list);

    }


}
